<template>
  <div class="login" ref="loginRef">
    <div class="b1 bg" />
    <div class="b2 bg" />
    <div class="b3 bg" />
    <div class="container">
      <div class="box">
        <div class="login_box" :style="{ opacity: loginBoxOpacy }">
          <div class="avatar">
            <img :src="QNURL + userAvatar" alt="" />
            <!-- <img src="@/assets/images/avatar.jpg" alt="" /> -->
          </div>
          <div class="login_form">
            <el-form
              ref="loginRuleFormRef"
              :model="loginRuleForm"
              :rules="loginRules"
              class="demo-ruleForm"
              status-icon
            >
              <el-form-item prop="username">
                <el-input
                  :prefix-icon="User"
                  placeholder="邮箱"
                  v-model="loginRuleForm.username"
                />
              </el-form-item>
              <el-form-item prop="password">
                <el-input
                  type="password"
                  placeholder="密码"
                  :prefix-icon="Lock"
                  v-model="loginRuleForm.password"
                />
              </el-form-item>
            </el-form>
          </div>
          <div class="op">
            <button @click="btnClick">
              {{ loading ? "loading..." : "登入" }}
            </button>
            <div class="text-op">
              <el-checkbox
                v-model="rememberPwd"
                label="记住密码"
                @change="rememberPwdChange"
                size="large"
              />
              <span @click="goRegister">没有账号？去注册！</span>
            </div>
          </div>
        </div>
        <div
          class="regiester_box"
          :style="{
            top: regiesterBoxTop + 'px',
            left: regiesterBoxLeft + 'px'
          }"
        >
          <div class="l">
            <div class="title">注册账号</div>
            <div class="regiester_form">
              <el-form
                ref="regiesterRuleFormRef"
                :model="regiesterRuleForm"
                :rules="regiesterRules"
                class="demo-ruleForm"
                status-icon
              >
                <el-form-item prop="nickname">
                  <el-input
                    :prefix-icon="User"
                    v-model="regiesterRuleForm.nickname"
                    placeholder="昵称"
                  />
                </el-form-item>
                <el-form-item prop="username">
                  <el-input
                    :prefix-icon="User"
                    v-model="regiesterRuleForm.username"
                    placeholder="邮箱"
                  />
                </el-form-item>
                <el-form-item prop="password">
                  <el-input
                    type="password"
                    :prefix-icon="Lock"
                    placeholder="密码"
                    v-model="regiesterRuleForm.password"
                  />
                </el-form-item>
                <el-form-item prop="comfirmPassword">
                  <el-input
                    type="password"
                    :prefix-icon="Lock"
                    placeholder="确认密码"
                    v-model="regiesterRuleForm.comfirmPassword"
                  />
                </el-form-item>
              </el-form>
            </div>
            <div class="op">
              <button @click="regiester">
                {{ loading ? "loading..." : "注册" }}
              </button>
              <div class="register_text-op text-op">
                <span @click="goLogin">已有账号！去登入！！！</span>
              </div>
            </div>
          </div>
          <div class="r">
            <div class="verify_form">
              <div class="title">验证邮箱</div>
              <div class="tip">
                {{
                  emailInSend
                    ? "验证码发送中，请稍后..."
                    : "验证码已发送到你的邮箱，请注意查收！"
                }}
              </div>
              <el-form
                ref="verifyFormRef"
                :model="verifyForm"
                :rules="verifyRules"
                class="demo-ruleForm"
                status-icon
              >
                <el-form-item prop="code">
                  <el-input
                    :prefix-icon="Coin"
                    placeholder="验证码"
                    v-model="verifyForm.code"
                  />
                </el-form-item>
              </el-form>
              <div class="op" style="margin-top: 50px">
                <button @click="verifyHandle">
                  {{ loading ? "loading..." : "验证" }}
                </button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Lock, User, Coin } from "@element-plus/icons-vue";
import { useLogin } from "./hook";
import { QNURL } from "@/config/urlConfig";

const {
  loginRuleFormRef,
  regiesterRuleFormRef,
  verifyFormRef,
  loginRuleForm,
  regiesterRuleForm,
  verifyRules,
  regiesterRules,
  loginRules,
  rememberPwd,
  regiesterBoxTop,
  loginBoxOpacy,
  regiesterBoxLeft,
  verifyForm,
  loading,
  loginRef,
  emailInSend,
  userAvatar,
  goRegister,
  regiester,
  rememberPwdChange,
  btnClick,
  goLogin,
  verifyHandle
} = useLogin();
</script>

<style lang="scss" scoped>
.bg {
  width: 100%;
  height: 100vh;
  position: relative;
  overflow: hidden;
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.b1 {
  background-image: url("@/assets/images/1.jpg");
}

.b2 {
  background-image: url("@/assets/images/2.jpg");
}

.b3 {
  background-image: url("@/assets/images/3.jpg");
}

$input-height: 35px;
$input-width: 280px;
.login {
  width: 100vw;
  height: 100vh;
  // background-color: #150137;
  overflow-y: scroll;
  // display: flex;
  // align-items: center;
  // justify-content: center;
  position: relative;
  // background-image: url("@/assets/images/8.jpg");
  // background-size: cover;
  user-select: none;

  &::-webkit-scrollbar {
    width: 0;
  }

  &:deep(.el-icon) {
    color: #dcdfe6 !important;
  }

  &:deep(.el-input__wrapper) {
    border-radius: 50px;
    background-color: transparent;
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
    // box-shadow: 0 0 0 1px var(--el-input-hover-border-color) inset;
    color: #fff;
  }

  &:deep(.el-input__inner) {
    height: $input-height;
    border-radius: 50px;
    color: #fff;
    border: none;

    &::placeholder {
      color: #dcdfe6;
    }
  }

  &:deep(.is-focus) {
    // box-shadow: 0 0 0 1px #ccc inset;
  }

  &:deep(.el-checkbox) {
    color: #fff;

    // .el-checkbox__label {
    //   color: #be1c83;
    // }
  }
  &:deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
    color: #fff;
  }

  &:deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
    // background-color: #be1c83;
    // border-color: #be1c83;
  }
}

$container-width: 680px;
$container-height: 500px;

.container {
  width: $container-width;
  height: $container-height;
  background-color: rgba(184, 183, 186, 0.1);
  border-radius: 20px;
  // border: 2px solid #777;
  backdrop-filter: blur(15px);
  padding: 20px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px 1px #505053;

  .box {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
  }
}
.login_box,
.regiester_box {
  .avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 30px;
    border: 2px solid #fff;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .login_form,
  .regiester_form,
  .verify_form {
    width: $input-width;
  }

  .op {
    margin-top: 10px;

    button {
      width: $input-width;
      height: $input-height;
      border-radius: 50px;
      border: none;
      cursor: pointer;
      color: #fff;
      font-weight: bold;
      font-size: 16px;
      background-color: #409eff;
    }

    .text-op {
      width: 100%;
      margin-top: 30px;
      color: #fff;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 13px;
      padding: 0 5px;

      span {
        cursor: pointer;
      }
    }

    .register_text-op {
      justify-content: center;
    }
  }
}

.login_box {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  // display: none;
  opacity: 1;
  transition: all 500ms;
}

.regiester_box {
  position: absolute;
  width: 200%;
  height: 100%;
  left: 0;
  top: 460px;
  transition: all 500ms;
  display: flex;
  // top: 0;
  // left: -636px;

  .l,
  .r {
    width: 50%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    .title {
      height: 50px;
      font-size: 28px;
      margin-bottom: 20px;
      color: #fff;
      text-align: center;
      font-weight: bold;
    }
  }

  .r {
    .title {
      height: 30px;
    }
    .tip {
      height: 40px;
      margin-top: 30px;
      margin-bottom: 50px;
      color: #fff;
      line-height: 30px;
      font-size: 18px;
      text-align: center;
    }
  }
}
</style>
